#include "./main.h"
#include <stdio.h>

void imx6ul_hardfpu_enable(void);

/**
 * @brief main函数
 *
 * @return int
 */
int main(void) {

  imx6ul_hardfpu_enable(); /* 使能I.MX6U的硬件NEON和FPU */
  int_init();              /* 初始化中断(一定要最先调用！) */
  imx6u_clkinit();         /* 初始化系统时钟 			*/
  clk_enable();            /* 使能所有的时钟 			*/
  led_init();              /* 初始化led 			*/

  lcd_init();
  /* 初始化触摸屏					*/
  gt1151_init();
  if (gt_init_fail == 1) // 判断gt系列初始化是否失败
  {
    printf("gt系列初始化失败 \r\n");
  }
  while (1) {
    tftlcd_dev.forecolor = LCD_RED;
    lcd_show_string(40, 40, 150, 32, 32, (char *)"TP Num :");
    lcd_show_string(40, 80, 150, 32, 32, (char *)"Point0 X:");
    lcd_show_string(40, 120, 150, 32, 32, (char *)"Point0 Y:");
    lcd_show_string(40, 160, 150, 32, 32, (char *)"Point1 X:");
    lcd_show_string(40, 200, 150, 32, 32, (char *)"Point1 Y:");
    lcd_show_string(40, 240, 150, 32, 32, (char *)"Point2 X:");
    lcd_show_string(40, 280, 150, 32, 32, (char *)"Point2 Y:");
    lcd_show_string(40, 320, 150, 32, 32, (char *)"Point3 X:");
    lcd_show_string(40, 360, 150, 32, 32, (char *)"Point3 Y:");
    lcd_show_string(40, 400, 150, 32, 32, (char *)"Point4 X:");
    lcd_show_string(40, 440, 150, 32, 32, (char *)"Point4 Y:");
    if (gt1151_dev.intflag == 1) {
      gt1151_dev.intflag = 0;
      tftlcd_dev.forecolor = LCD_BLUE;
      lcd_shownum(180, 40, gt1151_dev.point_num, 1, 32);
      lcd_shownum(180, 80, gt1151_dev.x[0], 5, 32);
      lcd_shownum(180, 120, gt1151_dev.y[0], 5, 32);
      lcd_shownum(180, 160, gt1151_dev.x[1], 5, 32);
      lcd_shownum(180, 200, gt1151_dev.y[1], 5, 32);
      lcd_shownum(180, 240, gt1151_dev.x[2], 5, 32);
      lcd_shownum(180, 280, gt1151_dev.y[2], 5, 32);
      lcd_shownum(180, 320, gt1151_dev.x[3], 5, 32);
      lcd_shownum(180, 360, gt1151_dev.y[3], 5, 32);
      lcd_shownum(180, 400, gt1151_dev.x[4], 5, 32);
      lcd_shownum(180, 440, gt1151_dev.y[4], 5, 32);

      lcd_show_string(310, 40, 150, 32, 32, (char *)"size :");
      lcd_shownum(350, 80, gt1151_dev.x_size[0], 5, 32);
      lcd_shownum(350, 120, gt1151_dev.y_size[0], 5, 32);
      lcd_shownum(350, 160, gt1151_dev.x_size[1], 5, 32);
      lcd_shownum(350, 200, gt1151_dev.y_size[1], 5, 32);
      lcd_shownum(350, 240, gt1151_dev.x_size[2], 5, 32);
      lcd_shownum(350, 280, gt1151_dev.y_size[2], 5, 32);
      lcd_shownum(350, 320, gt1151_dev.x_size[3], 5, 32);
      lcd_shownum(350, 360, gt1151_dev.y_size[3], 5, 32);
      lcd_shownum(350, 400, gt1151_dev.x_size[4], 5, 32);
      lcd_shownum(350, 440, gt1151_dev.y_size[4], 5, 32);
    }
  }

  return 0;
}

/*
 * @description	: 使能I.MX6U的硬件NEON和FPU
 * @param 		: 无
 * @return 		: 无
 */
void imx6ul_hardfpu_enable(void) {
  uint32_t cpacr;
  uint32_t fpexc;

  /* 使能NEON和FPU */
  cpacr = __get_CPACR();
  cpacr = (cpacr & ~(CPACR_ASEDIS_Msk | CPACR_D32DIS_Msk)) |
          (3UL << CPACR_cp10_Pos) | (3UL << CPACR_cp11_Pos);
  __set_CPACR(cpacr);
  fpexc = __get_FPEXC();
  fpexc |= 0x40000000UL;
  __set_FPEXC(fpexc);
}